package hu.debrecen.adastra.card.service;

import hu.debrecen.adastra.card.repository.domain.Account;
import hu.debrecen.adastra.card.service.impl.SnapszerCardGame;
import hu.debrecen.adastra.card.service.impl.ZsirozasCardGame;

import java.util.UUID;

public class CardGameFactory {

	private final PlayerStatisticsService playerStatisticsService;

	public enum GameType {
		SNAPSZER, ZSIR
	}

	public CardGameFactory(final PlayerStatisticsService playerStatisticsService) {
		super();
		this.playerStatisticsService = playerStatisticsService;
	}

	public AbstractGame<?> createDefaultCardGame(final Account player) {
		return this.createCardGame(player, null);
	}

	public AbstractGame<?> createCardGame(final Account player, final String type) {

		GameType gameType = this.resolveGameType(type);

		if(GameType.ZSIR.equals(gameType)) {
			return new ZsirozasCardGame(this.createGameId(), player, this.playerStatisticsService);
		}

		if(GameType.SNAPSZER.equals(gameType)) {
			return new SnapszerCardGame(this.createGameId(), player, this.playerStatisticsService);
		}


		throw new IllegalStateException("There is not any implementation for '"+type+"' gameType");
	}

	private GameType resolveGameType(final String type) {
		GameType gameType = null;
		if(type == null) {
			gameType = GameType.ZSIR;
		} else {
			gameType = GameType.valueOf(type.toUpperCase());
		}
		return gameType;
	}

	private String createGameId() {
		return UUID.randomUUID().toString();
	}

}
